package com.sxhalo.fsms.controller;


import com.sxhalo.fsms.domain.ScheduledTask;
import com.sxhalo.fsms.service.ScheduledTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/scheduled")
public class ScheduledController {

    @Autowired
    private ScheduledTaskService taskService;
    /**
     * 所有任务列表
     */
    @ResponseBody
    @RequestMapping("/scheduled")
    public List<ScheduledTask> taskList() {
        return taskService.taskList();
    }

    /**
     * 根据任务key => 启动任务
     */
    @ResponseBody
    @RequestMapping("/start")
    public String start(@RequestParam("taskKey") String taskKey) {
        taskService.start(taskKey);
        return "start success";
    }

    /**
     * 根据任务key => 停止任务
     */
    @ResponseBody
    @RequestMapping("/stop")
    public String stop(@RequestParam("taskKey") String taskKey) {
        taskService.stop(taskKey);
        return "stop success";
    }

    /**
     * 根据任务key => 重启任务
     */
    @ResponseBody
    @RequestMapping("/restart")
    public String restart(@RequestParam("taskKey") String taskKey) {
        taskService.restart(taskKey);
        return "restart success";
    }

}